package com.tcpConnection;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

public class TcpClient {

    public static void main(String[] args) throws IOException {
        //1.服务器ip地址，端口号
        InetAddress serverIp = InetAddress.getByName("127.0.0.1");
        int port = 9999;
        //2.创建一个socket连接
        Socket socket = new Socket(serverIp, port);
        //3.发送消息，IO流
        OutputStream os = socket.getOutputStream();
        try (socket;os){
            //将字符串转为字节形式
            os.write("你好，socket通信".getBytes());

        } catch (Exception e) {
            System.out.println(e.getMessage());
        }/*finally {
            os.write("你好".getBytes());
        }
*/
    }

}
